package app.negocio;

import java.util.List;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.Query;

import app.entidad.Persona;



public class PersonaDAO {
	@Inject
	private EntityManager em;
	
	public void insert(Persona c){
		em.persist(c);
	}
	
public void update(Persona p){
		
		em.merge(p);
		
	}

	public Persona read(String id){
		Persona m = em.find(Persona.class, id);
		return m;
	}
	
	public void Delete(Persona p){
		Persona	per=findById(p.getCedula());
			System.out.println("============PERSONA dao====================");
			System.out.println("imprime p "+p);
			em.remove(per);
			em.flush();
		}
	
	
public Persona findById(String cedula){
		
		System.out.println("============PERSONA DAO ====================");
		System.out.println("FIND "+em.find(Persona.class, cedula));
		return em.find(Persona.class, cedula);
		
	}
public List<Persona> getCliente(){
		
		String sql = "SELECT c From Persona c WHERE c.per_cedula = :per_cedula";
		
		Query q =  em.createQuery(sql, Persona.class);
		
		
		List<Persona> lst = q.getResultList();
		
		return lst;
	}


}
